import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import { getCurrentOrganizationId, isTenantRoleLevel } from 'utils/utils';
import request from 'utils/request';
import { CPAAS_MSG } from 'utils/config';
var organizationId = getCurrentOrganizationId();
var isSiteFlag = !isTenantRoleLevel();
var apiPrefix = isSiteFlag ? "".concat(CPAAS_MSG, "/v1/email/servers") : "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/email/servers");
var filterPrefix = isSiteFlag ? "".concat(CPAAS_MSG, "/v1/email-filters") : "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/email-filters");
/**
 * 查询邮箱账户数据
 * @async
 * @function fetchEmailData
 * @param {Object} params - 查询参数
 */

export function fetchEmail(_x) {
  return _fetchEmail.apply(this, arguments);
}
/**
 * 查询邮箱账户服务器配置项
 * @async
 * @function fetchEmailData
 * @param {Object} params - 查询参数
 * @param {String} params.serverId - 邮箱账号Id
 */

function _fetchEmail() {
  _fetchEmail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            return _context.abrupt("return", request("".concat(apiPrefix), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _fetchEmail.apply(this, arguments);
}

export function queryEmailServers(_x2) {
  return _queryEmailServers.apply(this, arguments);
}
/**
 * 新建邮箱账户
 * @async
 * @function fetchEmailData
 * @param {Object} params - 查询参数
 */

function _queryEmailServers() {
  _queryEmailServers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(apiPrefix, "/").concat(params.serverId), {
              method: 'GET'
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _queryEmailServers.apply(this, arguments);
}

export function createEmail(_x3) {
  return _createEmail.apply(this, arguments);
}
/**
 * 更新邮箱账户
 * @async
 * @function fetchEmailData
 * @param {Object} params - 查询参数
 */

function _createEmail() {
  _createEmail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(apiPrefix), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _createEmail.apply(this, arguments);
}

export function updateEmail(_x4) {
  return _updateEmail.apply(this, arguments);
}

function _updateEmail() {
  _updateEmail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(apiPrefix), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _updateEmail.apply(this, arguments);
}

export function deleteEmail(_x5) {
  return _deleteEmail.apply(this, arguments);
}
/**
 * 黑白名单列表
 * @async
 * @function fetchFilterList
 * @param {Object} params - 查询参数
 */

function _deleteEmail() {
  _deleteEmail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            return _context5.abrupt("return", request("".concat(apiPrefix), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _deleteEmail.apply(this, arguments);
}

export function fetchFilterList(_x6) {
  return _fetchFilterList.apply(this, arguments);
}
/**
 * 更新黑白名单
 * @async
 * @function fetchFilterList
 * @param {Object} params - 查询参数
 */

function _fetchFilterList() {
  _fetchFilterList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            return _context6.abrupt("return", request("".concat(filterPrefix), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _fetchFilterList.apply(this, arguments);
}

export function updateFilter(_x7) {
  return _updateFilter.apply(this, arguments);
}
/**
 * 删除黑白名单
 * @async
 * @function fetchFilterList
 * @param {Object} params - 查询参数
 */

function _updateFilter() {
  _updateFilter = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(params) {
    return _regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            return _context7.abrupt("return", request("".concat(filterPrefix), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  }));
  return _updateFilter.apply(this, arguments);
}

export function deleteFilter(_x8) {
  return _deleteFilter.apply(this, arguments);
}

function _deleteFilter() {
  _deleteFilter = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(params) {
    return _regeneratorRuntime.wrap(function _callee8$(_context8) {
      while (1) {
        switch (_context8.prev = _context8.next) {
          case 0:
            return _context8.abrupt("return", request("".concat(filterPrefix), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context8.stop();
        }
      }
    }, _callee8);
  }));
  return _deleteFilter.apply(this, arguments);
}